package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.滑动窗口;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/16 12:16
 */
public class 字符串中最大的3位相同数字 {
    //https://leetcode.cn/problems/largest-3-same-digit-number-in-string/
    public String largestGoodInteger(String num) {
        int last = 0;
        int len = 3;
        int x = -1;
        for (int i = 0; i < num.length(); i++) {
            while (i < num.length() && num.charAt(i) == num.charAt(last)) {
                i++;
                if (i - last == len)
                    break;
            }
            if (i - last == len) {
                x = Math.max(x, num.charAt(last) - '0');
            }

            last = i;
        }
        if (num.length() - last == 3) {
            x = Math.max(x, num.charAt(last) - '0');
        }
        if (x == 0)
            return "000";
        if (x == -1)
            return "";

        return String.valueOf(x * 100 + x * 10 + x);
    }

    public static void main(String[] args) {
        字符串中最大的3位相同数字 solution = new 字符串中最大的3位相同数字();
        String s = solution.largestGoodInteger("101010");
        System.out.println(s);
    }
}
